<?php

namespace App\Jobs;

use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class ReleaseUserFromGagList implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $id;

    /**
     * UpdateUserDiscussStatus constructor.
     * @param $user_id
     */
    public function __construct($user_id)
    {
        $this->id = $user_id;

    }

    /**
     * @param User $user
     */
    public function handle()
    {
        $data = [
            'gag_status' => User::NORMAL,
            'gag_duration' => null,
        ];

        //判断用户是否已经解冻,如果已解冻,则不执行更新
        $user = new User();

        $user = $user->find($this->id);

        if ($user && $user->gag_status == User::NORMAL && $user->gag_duration == null) {
            return;
        }

        $user->update($data);
    }

    public function failed(\Exception $e)
    {
        // 发送失败通知, etc...
    }
}
